<!DOCTYPE html>
<!--suppress ThymeleafVariablesResolveInspection-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/js/register/jquery-3.1.0.min.js}"></script>
</head>
<style>
    ::-webkit-scrollbar {display:none}/*隐藏横向滚动条但可以滚动*/
</style>
<body>
<form class="layui-form" id="m_form">
    <input type="hidden" name="depid" th:value="${dep.depid}">

    <div class="layui-form-item" style="margin-top: 20px;">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="depname" lay-verify="required" placeholder="请输入部门名称" autocomplete="off" class="layui-input" th:value="${dep.depname}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级部门</label>
        <div class="layui-input-block">
            <select name="parentid">
                <option value="0">请选择上级部门</option>
                <option th:each="d:${deps}"th:value="${d.depid}" th:text="${d.depname}" th:selected="${d.depid == dep.parentid}" th:if="${dep.parentid !=0}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">部门负责人</label>
        <div class="layui-input-block">
            <select name="chairman">
                <option th:value="${dep.chairman}" th:text="${dep.empname}" selected="true"></option>
                <option th:each="e:${emp}"th:value="${e.emp_id}" th:text="${e.emp_name}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" lay-verify="required" autocomplete="off" class="layui-input" th:value="${dep.remark}">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
        </div>
    </div>

</form>
</body>
<script type="text/javascript" th:inline="none">
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        //你可以在这里做操作  也可以不使用这个方法
        form.on('submit(formDemo)', function(data){

                    $.ajax({
                        url: '/dep/upd',
                        type: 'post',
                        data:data.field,
                        dataType: 'json',
                        success:function(data){
                            if(data){
                                layer.msg(JSON.stringify("修改成功"));
                                //先得到当前iframe层的索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //再执行关闭
                                parent.layer.close(index);
                                window.parent.location.reload();
                            }else{
                                $("#name").val("");
                                layer.msg('部门名称重复 修改失败', { icon: 5, time: 2000 });
                            }
                        },
                    })

            //$('.layui-laypage-btn').click();//刷新

            return false;
        });
    });
</script>
</html>